import Vue from 'vue'
import App from './App.vue'
import Antd from 'ant-design-vue'
import routerFunc from './router'
Vue.config.productionTip = false

Vue.use(Antd)

// qiankun 框架注入的参数 参数有值，则执行在父容器中运行
if (window.__POWERED_BY_QIANKUN__) {
    __webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__
}

// 独立运行时
if (!window.__POWERED_BY_QIANKUN__) {
    render()
}

// 路由实例
let router = null
// Vue 对象实例
let instance = null

/**
 * 应用启动函数
 *
 * @param props
 */
function render(props = {}) {

    const {container} = props
    router = routerFunc(window)
    instance = new Vue({
        router,
        render: h => h(App),
    }).$mount(container ? container.querySelector('#app') : '#app')
}

export async function bootstrap() {
    console.log('[vue] vue app bootstraped')
}

export async function mount(props) {
    console.log('[vue] props from main framework', props)
    render(props)
}

export async function unmount() {
    instance.$destroy()
    instance.$el.innerHTML = ''
    instance = null
    router = null
}